package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.view.View;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.isunland.managesystem.adapter.ShippingAdapter;
import com.isunland.managesystem.base.BaseListFragment;
import com.isunland.managesystem.base.BaseOriginal;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.RDistributionDetailSub;
import com.isunland.managesystem.entity.rDistributionMain;
import com.isunland.managesystem.utils.ParamsNotEmpty;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/7/25 13:52
 */
public class ShippingListFragment extends BaseListFragment {
  private rDistributionMain mItemMain;
  private ArrayList<RDistributionDetailSub> mList;
  private ShippingAdapter mAdapter;

  @Override public void initData() {
    super.initData();
    mItemMain = mBaseParams.getItem() instanceof rDistributionMain ? (rDistributionMain) mBaseParams
        .getItem() : new rDistributionMain();
    mList = new ArrayList<>();
    mAdapter = new ShippingAdapter(mActivity, mList);
  }

  @Override public void initView(View view, Bundle savedInstanceState) {
    super.initView(view, savedInstanceState);
    setTitleCustom("发货清单");
    setListAdapter(mAdapter);
  }

  @Override public String getUrl() {
    return ApiConst.URL_QUERY_LIST_SHIPPING;
  }

  @Override public HashMap<String, String> getparameters() {
    ParamsNotEmpty params = new ParamsNotEmpty();
    params.put("mainId", mItemMain.getId());
    return params.getParams();
  }

  @Override public void resolveResponse(String json) {
    BaseOriginal<RDistributionDetailSub> original =
        new Gson().fromJson(json, new TypeToken<BaseOriginal<RDistributionDetailSub>>() {
        }.getType());
    mList.clear();
    mList.addAll(original.getRows());
    mAdapter.notifyDataSetChanged();
  }
}
